package com.quasar.hpatient.module.mine_setting;

import android.content.Intent;

import com.quasar.hpatient.R;
import com.quasar.hpatient.module.mine_feedback.MineFeedbackActivity;
import com.quasar.hpatient.module.mine_password.MinePasswordActivity;
import com.quasar.hpatient.module.mine_phone.MinePhoneActivity;
import com.quasar.hpatient.module.mine_version.MineVersionActivity;

import lib.quasar.base.frame.BaseActivity;
import lib.quasar.db.manager.DBManager;
import lib.quasar.widget.button.SlideButton;

/**
 * description: 设置
 * created by kalu on 2018/3/27 10:44
 */
public class MineSettingActivity extends BaseActivity<MineSettingPresenter> implements MineSettingView {

    public final static int REQUEST_CODE = 1111;
    public final static int RESULT_CODE = 1112;

    @Override
    public int initView() {
        return R.layout.activity_mine_setting;
    }

    @Override
    public void initDataLocal() {

        findViewById(R.id.activity_setting_logout).setOnClickListener(v -> logout());
        findViewById(R.id.mine_setting_password).setOnClickListener(v -> goNext(MinePasswordActivity.class));
        findViewById(R.id.mine_setting_phone).setOnClickListener(v -> {
            final Intent intent = new Intent(getApplicationContext(), MinePhoneActivity.class);
            startActivityForResult(intent, REQUEST_CODE);
        });

        findViewById(R.id.mine_setting_feedback).setOnClickListener(v -> goNext(MineFeedbackActivity.class));
        findViewById(R.id.mine_setting_version).setOnClickListener(v -> goNext(MineVersionActivity.class));
        findViewById(R.id.mine_setting_help).setOnClickListener(v -> toast("使用帮助"));

        getPresenter().initConfig(this);
    }

    @Override
    public void initDataNet() {
    }

    @Override
    public void logout() {
        DBManager.getInstance().resetUserModel();
        setResult(RESULT_CODE);
        onBackPressed();
    }

    @Override
    public void setButton(int id, boolean enable) {

        SlideButton button = findViewById(id);
        if (null == button) return;
        button.setChecked(enable);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode != REQUEST_CODE || resultCode != MinePasswordActivity.RESULT_CODE) return;
        logout();
    }
}